package net.cyndeline.fov.mrpas.defaultImpl

import net.cyndeline.fov.mrpas.ObstructedAngles
import scala.collection.mutable.ArrayBuffer

class DefaultObstructedAngles extends ObstructedAngles {
  private val obstructedAngles = new ArrayBuffer[(Float, Float)]
  
  def addObstructedAngle(start: Float, stop: Float): Boolean = {
    if (angleValid(start, stop)) {
      obstructedAngles += ((start, stop))
      true
  	} else {
  	  false
  	}
  }
  
  def isObstructed(angle: Float, anglesToCheck: Int): Boolean = {
    for (index <- 0 until Math.min(obstructedAngles.size, Math.max(0, anglesToCheck))) {
      val obstructed = obstructedAngles(index)
      
      if (angle >= obstructed._1 && angle <= obstructed._2) {
        return true
      }
    }
    
    false
  }
  
  private def angleValid(start: Float, stop: Float): Boolean = {
    !(start > stop || start < 0 || start > 1 || stop < 0 || stop > 1)
  }
}